<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>混合区间管理</title>
</head>
<body>
    <div ng-app="MixSectionApp" ng-controller="MixSectionCtrl">
        <div class="row">
            <ui-container url="rule/mix/list" key="rule-mix-list-00">
                <ui-search-form>
                    <search-select class="col-md-3" name="direction">
                        <option value="">请选择配送类型</option>
                        <option value="0">配送</option>
                        <option value="1">上门换</option>
                        <option value="2">上门退</option>
                    </search-select>

                    <search-input class="col-md-3" name="supplierName" placeholder="请输入供货商名称"></search-input>

                </ui-search-form>
                <ui-table-tool>
                    <a  class="btn btn-sm btn-primary" href="javascript:void(0);" ng-click="addOpen('rule/mix/add.htm')" >新增</a>
                </ui-table-tool>
                <ui-table>

                </ui-table>
                <table-page/>
            </ui-container>
        </div>
        <div class="row" id="mixImport">
            <a  class="btn btn-sm btn-primary" href="javascript:void(0);" ng-click="exportDatas()" target="_blank" >下载模板</a>
            <a  class="btn btn-sm btn-success" href="./html/mixhelper.html" target="_blank" >导出帮助</a>
            <ui-upload url="rule/mix/import" success="uploadSuccess"></ui-upload>
        </div>
    </div>
<script>
    angular.module('MixSectionApp',['ui.table']);
    angular.module('MixSectionApp').controller('MixSectionCtrl', function($scope){
        $scope.uploadSuccess=function (returndata) {
            $("#mixImport").find(".upload-result").remove();
            if(returndata.data["fileKey"]){
                $("#mixImport").append('<a  class="btn btn-sm btn-success upload-result" href="rule/mix/down?fileKey='+returndata.data["fileKey"]+'" target="_blank" >下载导入失败的记录</a>');
            }
            toastr.success("总共"+returndata.data["totalNums"]+"条,成功"+returndata.data["successNums"]+"条");
        }
        $scope.exportDatas = function(){
            var params = {
                url: 'rule/mix/exporttemplate',
                type: "POST"
            };
            var exportForm = $("<form>");
            $(exportForm).css("display", "none");
            $(exportForm).attr('target', 'targetFrame');
            $(exportForm).attr('method', params.type);
            $(exportForm).attr('action', params.url);
            exportForm = exportForm.appendTo($("body"));
            exportForm.submit();
            exportForm.remove();
        }
        $scope.addOpen=function (url) {

            window.reloadTable=$scope['rule-mix-list-00']._queryData;
            window.location.href=url;
        }

        function doDel(selectedItems) {
            const uiContainerCtrl=$scope['rule-mix-list-00'];
            if(!selectedItems||selectedItems.length<=0){
                toastr.error("没有选中删除对象")
                return;
            }
            const ids=selectedItems.map(m=>m.id);
            $.ajax({
                url:'rule/mix/del',
                data:{ids:ids.join(",")}
            }).done(function (result) {
                if(result.code=='0000'){
                    toastr.success(result.msg);
                    uiContainerCtrl._queryData({});
                }else{
                    toastr.error(result.msg);
                }

            }).fail(function (r) {
                toastr.error("服务器异常"+r);

            });

        }

        $scope.addOrg=function (items) {
            console.info(items)
        }
        //每一列的操作按钮
        $scope._operateColumns=[{text:'编辑',click:function (data) {
            $scope.addOpen("rule/mix/update.htm?id="+data.id);
        }},{text:'删除',click:function (data) {
            doDel([data])
        }}]

        $scope._columns=[
            {name:'supplierName',head:'供货商',render(data,value){
                return (data.supplier&&data.supplier.name)?data.supplier.name : "";
            }},
            {name:'direction',head:'配送类型',render(data,value){
                switch (value+""){
                    case "0":
                        return "配送";
                    case "1":
                        return "上门换";
                    case "2":
                        return "上门退";
                    default:
                        return "";
                }
            }},
            {name:'pointLeft',head:'规则',render(data,value){
                    return data.valueRange.pointLeft+(data.valueRange.containLeft=='1'?"<=":"<")+" x "+(data.valueRange.containRight=='1'?"<=":"<")+data.valueRange.pointRight;
                }
            },
            {name:'fixWeight',head:'固定值',render(data,value){
                return (data.valueRange&&data.valueRange.fixWeight)? data.valueRange.fixWeight:"";
            }},
            {name:'firstPiecePrice',head:'首件单价/元'},
            {name:'secondPiecePrice',head:'拖件单价/元'},
            {name:'settlementType',head:'结算类型',render(data,value){
                switch (value+""){
                    case "0":
                        return "自营";
                    case "1":
                        return "合作站";
                    case "2":
                        return "合作商";
                    case "3":
                        return "大型合作商";
                    default:
                        return"";
                }
            }}


        ];
        $scope._btns=[{text:'删除',click:doDel}];
    });
</script>
</body>
</html>
